﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.MultiEditingInPathEditor.CCUISetLocationsParametersDialog
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.MultiEditingInPathEditor;

public class CCUISetLocationsParametersDialog : TxForm
{
  private Label m_parameterLabel;
  private Label m_valueLabel;
  private ComboBox m_attributesList;
  private ComboBox m_enumValueCtrl;
  private TextBox m_stringValueCtrl;
  private Button m_cancelButton;
  private Button m_okButton;
  private TxObjEditBoxCtrl m_frameValueCtrl;
  private NumericUpDown m_numericValueCtrl;
  private CCApSetLocationsParametersApp m_appManager;

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CCUISetLocationsParametersDialog));
    this.m_parameterLabel = new Label();
    this.m_valueLabel = new Label();
    this.m_attributesList = new ComboBox();
    this.m_enumValueCtrl = new ComboBox();
    this.m_stringValueCtrl = new TextBox();
    this.m_okButton = new Button();
    this.m_cancelButton = new Button();
    this.m_frameValueCtrl = new TxObjEditBoxCtrl();
    this.m_numericValueCtrl = new NumericUpDown();
    this.m_numericValueCtrl.BeginInit();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this.m_parameterLabel, "m_parameterLabel");
    this.m_parameterLabel.Name = "m_parameterLabel";
    componentResourceManager.ApplyResources((object) this.m_valueLabel, "m_valueLabel");
    this.m_valueLabel.Name = "m_valueLabel";
    this.m_attributesList.DropDownStyle = ComboBoxStyle.DropDownList;
    componentResourceManager.ApplyResources((object) this.m_attributesList, "m_attributesList");
    this.m_attributesList.Name = "m_attributesList";
    this.m_enumValueCtrl.DropDownStyle = ComboBoxStyle.DropDownList;
    componentResourceManager.ApplyResources((object) this.m_enumValueCtrl, "m_enumValueCtrl");
    this.m_enumValueCtrl.Name = "m_enumValueCtrl";
    this.m_enumValueCtrl.SelectedIndexChanged += new EventHandler(this.m_enumValueCtrl_SelectedIndexChanged);
    this.m_enumValueCtrl.KeyPress += new KeyPressEventHandler(this.m_enumValueCtrl_KeyPress);
    componentResourceManager.ApplyResources((object) this.m_stringValueCtrl, "m_stringValueCtrl");
    this.m_stringValueCtrl.Name = "m_stringValueCtrl";
    this.m_stringValueCtrl.TextChanged += new EventHandler(this.m_stringValueCtrl_TextChanged);
    this.m_stringValueCtrl.KeyPress += new KeyPressEventHandler(this.m_stringValueCtrl_KeyPress);
    componentResourceManager.ApplyResources((object) this.m_okButton, "m_okButton");
    this.m_okButton.Name = "m_okButton";
    this.m_okButton.Click += new EventHandler(this.m_okButton_Click);
    componentResourceManager.ApplyResources((object) this.m_cancelButton, "m_cancelButton");
    this.m_cancelButton.Name = "m_cancelButton";
    this.m_cancelButton.Click += new EventHandler(this.m_cancelButton_Click);
    this.m_frameValueCtrl.ListenToPick = true;
    componentResourceManager.ApplyResources((object) this.m_frameValueCtrl, "m_frameValueCtrl");
    ((Control) this.m_frameValueCtrl).Name = "m_frameValueCtrl";
    this.m_frameValueCtrl.Object = (ITxObject) null;
    this.m_frameValueCtrl.PickLevel = (TxPickLevel) 1;
    this.m_frameValueCtrl.ReadOnly = false;
    this.m_frameValueCtrl.ValidatorType = (TxValidatorType) 6;
    this.m_frameValueCtrl.TypeInvalid += new EventHandler(this.m_frameValueCtrl_TypeInvalid);
    this.m_frameValueCtrl.TypeValid += new EventHandler(this.m_frameValueCtrl_TypeValid);
    this.m_frameValueCtrl.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.m_frameValueCtrl_Picked);
    ((Control) this.m_frameValueCtrl).KeyPress += new KeyPressEventHandler(this.m_frameValueCtrl_KeyPress);
    this.m_numericValueCtrl.DecimalPlaces = 2;
    componentResourceManager.ApplyResources((object) this.m_numericValueCtrl, "m_numericValueCtrl");
    this.m_numericValueCtrl.Maximum = new Decimal(new int[4]
    {
      99999,
      0,
      0,
      0
    });
    this.m_numericValueCtrl.Minimum = new Decimal(new int[4]
    {
      99999,
      0,
      0,
      int.MinValue
    });
    this.m_numericValueCtrl.Name = "m_numericValueCtrl";
    this.m_numericValueCtrl.ValueChanged += new EventHandler(this.m_numericValueCtrl_ValueChanged);
    this.m_numericValueCtrl.KeyPress += new KeyPressEventHandler(this.m_numericValueCtrl_KeyPress);
    componentResourceManager.ApplyResources((object) this, "$this");
    ((Control) this).Controls.Add((Control) this.m_numericValueCtrl);
    ((Control) this).Controls.Add((Control) this.m_frameValueCtrl);
    ((Control) this).Controls.Add((Control) this.m_stringValueCtrl);
    ((Control) this).Controls.Add((Control) this.m_cancelButton);
    ((Control) this).Controls.Add((Control) this.m_okButton);
    ((Control) this).Controls.Add((Control) this.m_enumValueCtrl);
    ((Control) this).Controls.Add((Control) this.m_attributesList);
    ((Control) this).Controls.Add((Control) this.m_valueLabel);
    ((Control) this).Controls.Add((Control) this.m_parameterLabel);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CCUISetLocationsParametersDialog);
    this.SemiModal = false;
    ((Form) this).ShowIcon = false;
    ((Form) this).Load += new EventHandler(this.CCUISetLocationsParametersDialog_Load);
    this.m_numericValueCtrl.EndInit();
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }

  public CCUISetLocationsParametersDialog()
  {
    this.InitializeComponent();
    this.m_appManager = new CCApSetLocationsParametersApp();
  }

  private void InitAttributeComboBox()
  {
    ArrayList arrayList = new ArrayList();
    foreach (string attributes in CCApSetLocationsParametersApp.AttributesList)
    {
      AttributeComboBoxItem attributeComboBoxItem = new AttributeComboBoxItem(((CApAttributeInfo) CCApSetLocationsParametersApp.AttributesInfoHashTable[(object) attributes]).Name, attributes);
      arrayList.Add((object) attributeComboBoxItem);
    }
    this.m_attributesList.DataSource = (object) arrayList;
    this.m_attributesList.DisplayMember = "AttributeName";
    this.m_attributesList.ValueMember = "AttributeId";
    if (CCApSetLocationsParametersApp.LastEditedAttributeId != "")
      this.m_attributesList.SelectedIndex = CCApSetLocationsParametersApp.AttributesList.IndexOf((object) CCApSetLocationsParametersApp.LastEditedAttributeId);
    this.m_attributesList.SelectedIndexChanged += new EventHandler(this.m_attributesList_SelectedIndexChanged);
  }

  private void VisualiseAppropriateValueControl()
  {
    string attributeId = ((AttributeComboBoxItem) this.m_attributesList.SelectedItem).AttributeId;
    CApAttributeInfo capAttributeInfo = (CApAttributeInfo) CCApSetLocationsParametersApp.AttributesInfoHashTable[(object) attributeId];
    this.DisplayParameterValueInAppropriateControl(capAttributeInfo.ValidLocationType, capAttributeInfo.Id, capAttributeInfo.DisplayType, capAttributeInfo.Name, attributeId);
  }

  private void DisplayParameterValueInAppropriateControl(
    validLocationType locType,
    string attributeId,
    displayType type,
    string attributeName,
    string itemId)
  {
    try
    {
      switch (type)
      {
        case displayType.STRING:
          this.DisplayStringParameterValue(locType, attributeId);
          break;
        case displayType.INT:
        case displayType.DOUBLE:
          this.DisplayNumericParameterValue(locType, attributeId, attributeName, type, itemId);
          break;
        case displayType.FRAME:
          this.DisplayFrameParameterValue(locType, attributeId);
          break;
        case displayType.COMBOBOX:
          this.DisplayEnumerationParameterValue(locType, attributeId, attributeName, itemId);
          break;
      }
    }
    catch (Exception ex)
    {
      this.m_okButton.Enabled = false;
    }
  }

  private void DisplayStringParameterValue(validLocationType locType, string attributeId)
  {
    this.m_stringValueCtrl.Visible = true;
    this.m_enumValueCtrl.Visible = false;
    this.m_numericValueCtrl.Visible = false;
    ((Control) this.m_frameValueCtrl).Visible = false;
    this.m_stringValueCtrl.Text = "";
    this.m_okButton.Enabled = true;
    if (this.m_appManager.CheckLocationsType(locType))
    {
      try
      {
        if (attributeId == "DEFAULT_COMMENT")
          this.m_stringValueCtrl.Text = this.m_appManager.GetCommonCommentParamValueFromLocations();
        else
          this.m_stringValueCtrl.Text = this.m_appManager.GetCommonStrParamValueFromLocations(attributeId);
        if (this.m_stringValueCtrl.Text == "")
          this.m_okButton.Enabled = false;
        this.m_stringValueCtrl.Focus();
      }
      catch (Exception ex)
      {
        this.m_stringValueCtrl.Enabled = false;
        this.m_okButton.Enabled = false;
      }
    }
    else
    {
      this.m_stringValueCtrl.Enabled = false;
      this.m_okButton.Enabled = false;
    }
  }

  private void DisplayNumericParameterValue(
    validLocationType locType,
    string attributeId,
    string attributeName,
    displayType type,
    string ParamKeyInHash)
  {
    this.m_stringValueCtrl.Visible = false;
    this.m_enumValueCtrl.Visible = false;
    this.m_numericValueCtrl.Visible = true;
    ((Control) this.m_frameValueCtrl).Visible = false;
    this.m_okButton.Enabled = true;
    if (this.m_appManager.CheckLocationsType(locType))
    {
      CApNumericAttributeInfo numericAttributeInfo = (CApNumericAttributeInfo) CCApSetLocationsParametersApp.AttributesInfoHashTable[(object) ParamKeyInHash];
      this.m_numericValueCtrl.Value = 0M;
      this.m_numericValueCtrl.Minimum = numericAttributeInfo.MinVal;
      this.m_numericValueCtrl.Maximum = numericAttributeInfo.MaxVal;
      this.m_numericValueCtrl.Increment = 1M;
      if (type == displayType.INT)
      {
        int paramVal = 0;
        if (this.m_appManager.GetCommonIntParamValueFromLocations(attributeId, ref paramVal))
          this.m_numericValueCtrl.Value = (Decimal) paramVal;
        else
          this.m_okButton.Enabled = false;
      }
      else
      {
        double paramVal = 0.0;
        if (this.m_appManager.GetCommonDoubleParamValueFromLocations(attributeId, ref paramVal))
          this.m_numericValueCtrl.Value = (Decimal) paramVal;
        else
          this.m_okButton.Enabled = false;
      }
      this.m_numericValueCtrl.Focus();
    }
    else
    {
      this.m_numericValueCtrl.Enabled = false;
      this.m_okButton.Enabled = false;
    }
  }

  private void DisplayEnumerationParameterValue(
    validLocationType locType,
    string attributeId,
    string attributeName,
    string ParamKeyInHash)
  {
    this.m_stringValueCtrl.Visible = false;
    this.m_enumValueCtrl.Visible = true;
    this.m_numericValueCtrl.Visible = false;
    ((Control) this.m_frameValueCtrl).Visible = false;
    this.m_okButton.Enabled = true;
    if (this.m_appManager.CheckLocationsType(locType))
    {
      CApEnumAttributeInfo enumAttributeInfo = (CApEnumAttributeInfo) CCApSetLocationsParametersApp.AttributesInfoHashTable[(object) ParamKeyInHash];
      this.m_enumValueCtrl.DataSource = (object) enumAttributeInfo.EnumItems;
      this.m_enumValueCtrl.DisplayMember = "Name";
      this.m_enumValueCtrl.ValueMember = "Value";
      this.m_enumValueCtrl.Focus();
      try
      {
        int num = -1;
        if (enumAttributeInfo.ValueType == valueType.INT)
        {
          int paramVal = 0;
          if (this.m_appManager.GetCommonIntParamValueFromLocations(attributeId, ref paramVal))
          {
            for (int index = 0; index < enumAttributeInfo.EnumItems.Count; ++index)
            {
              if ((int) ((CApEnumAttributeItem) enumAttributeInfo.EnumItems[index]).Value == paramVal)
              {
                num = index;
                break;
              }
            }
          }
        }
        else if (enumAttributeInfo.ValueType == valueType.STRING)
        {
          string valueFromLocations = this.m_appManager.GetCommonStrParamValueFromLocations(attributeId);
          for (int index = 0; index < enumAttributeInfo.EnumItems.Count; ++index)
          {
            if ((string) ((CApEnumAttributeItem) enumAttributeInfo.EnumItems[index]).Value == valueFromLocations)
            {
              num = index;
              break;
            }
          }
        }
        this.m_enumValueCtrl.SelectedIndex = num;
        if (num != -1)
          return;
        this.m_okButton.Enabled = false;
      }
      catch (Exception ex)
      {
        this.m_okButton.Enabled = false;
      }
    }
    else
    {
      this.m_enumValueCtrl.Enabled = false;
      this.m_okButton.Enabled = false;
    }
  }

  private void DisplayFrameParameterValue(validLocationType locType, string attributeId)
  {
    this.m_stringValueCtrl.Visible = false;
    this.m_enumValueCtrl.Visible = false;
    this.m_numericValueCtrl.Visible = false;
    ((Control) this.m_frameValueCtrl).Visible = true;
    this.m_frameValueCtrl.Object = (ITxObject) null;
    this.m_okButton.Enabled = true;
    if (this.m_appManager.CheckLocationsType(locType))
    {
      this.m_frameValueCtrl.Focus();
      TxFrame valueFromLocations = this.m_appManager.GetCommonFrameParamValueFromLocations(attributeId);
      if (TxFrame.op_Inequality(valueFromLocations, (ITxObject) null))
      {
        this.m_frameValueCtrl.Object = (ITxObject) valueFromLocations;
        this.m_frameValueCtrl.Focus();
      }
      else
        this.m_okButton.Enabled = false;
    }
    else
    {
      this.m_frameValueCtrl.Enabled = false;
      this.m_okButton.Enabled = false;
    }
  }

  private void SetEditedAttributeOnLocations()
  {
    try
    {
      if (this.m_enumValueCtrl.Visible)
        this.SetEnumAttributeOnLocations();
      else if (this.m_numericValueCtrl.Visible)
        this.SetNumericAttributeOnLocations();
      else if (this.m_stringValueCtrl.Visible)
      {
        this.SetStringAttributeOnLocations();
      }
      else
      {
        if (!((Control) this.m_frameValueCtrl).Visible)
          return;
        this.SetFrameAttributeOnLocations();
      }
    }
    catch (Exception ex)
    {
      int num = (int) TxMessageBox.Show("Fail to set the parameter on the selected location(s)", ((Control) this).Text, MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
  }

  private void SetEnumAttributeOnLocations()
  {
    CApEnumAttributeInfo enumAttributeInfo = (CApEnumAttributeInfo) CCApSetLocationsParametersApp.AttributesInfoHashTable[(object) ((AttributeComboBoxItem) this.m_attributesList.SelectedItem).AttributeId];
    string id = enumAttributeInfo.Id;
    if (enumAttributeInfo.ValueType == valueType.INT)
    {
      int selectedIndex = this.m_enumValueCtrl.SelectedIndex;
      int paramVal = (int) ((CApEnumAttributeItem) enumAttributeInfo.EnumItems[selectedIndex]).Value;
      this.m_appManager.SetLocationsIntParamValue(id, paramVal);
    }
    else
    {
      int selectedIndex = this.m_enumValueCtrl.SelectedIndex;
      string paramVal = (string) ((CApEnumAttributeItem) enumAttributeInfo.EnumItems[selectedIndex]).Value;
      this.m_appManager.SetLocationsStrParamValue(id, paramVal);
    }
  }

  private void SetNumericAttributeOnLocations()
  {
    string attributeId = ((AttributeComboBoxItem) this.m_attributesList.SelectedItem).AttributeId;
    string id = ((CApAttributeInfo) CCApSetLocationsParametersApp.AttributesInfoHashTable[(object) attributeId]).Id;
    double paramVal = (double) this.m_numericValueCtrl.Value;
    if (((CApAttributeInfo) CCApSetLocationsParametersApp.AttributesInfoHashTable[(object) attributeId]).ValueType == valueType.INT)
      this.m_appManager.SetLocationsIntParamValue(id, (int) paramVal);
    else
      this.m_appManager.SetLocationsDoubleParamValue(id, paramVal);
  }

  private void SetStringAttributeOnLocations()
  {
    string id = ((CApAttributeInfo) CCApSetLocationsParametersApp.AttributesInfoHashTable[(object) ((AttributeComboBoxItem) this.m_attributesList.SelectedItem).AttributeId]).Id;
    string text = this.m_stringValueCtrl.Text;
    if (id == "DEFAULT_COMMENT")
      this.m_appManager.SetLocationCommonCommentParamValue(text);
    else
      this.m_appManager.SetLocationsStrParamValue(id, text);
  }

  private void SetFrameAttributeOnLocations()
  {
    this.m_appManager.SetLocationsFrameParamValue(((CApAttributeInfo) CCApSetLocationsParametersApp.AttributesInfoHashTable[(object) ((AttributeComboBoxItem) this.m_attributesList.SelectedItem).AttributeId]).Id, this.m_frameValueCtrl.Object);
  }

  private void m_attributesList_SelectedIndexChanged(object sender, EventArgs e)
  {
    this.VisualiseAppropriateValueControl();
  }

  private void CCUISetLocationsParametersDialog_Load(object sender, EventArgs e)
  {
    this.InitAttributeComboBox();
    this.VisualiseAppropriateValueControl();
  }

  private void m_cancelButton_Click(object sender, EventArgs e) => ((Form) this).Close();

  private void m_okButton_Click(object sender, EventArgs e)
  {
    TxApplication.ActiveDocument.UndoManager.StartTransaction();
    CCApSetLocationsParametersApp.LastEditedAttributeId = ((AttributeComboBoxItem) this.m_attributesList.SelectedItem).AttributeId;
    this.SetEditedAttributeOnLocations();
    TxApplication.ActiveDocument.UndoManager.EndTransaction();
    ((Form) this).Close();
  }

  private void m_frameValueCtrl_Picked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    if (TxFrame.op_Inequality(this.m_frameValueCtrl.Object as TxFrame, (ITxObject) null))
      this.m_okButton.Enabled = true;
    else
      this.m_okButton.Enabled = false;
  }

  private void m_frameValueCtrl_TypeValid(object sender, EventArgs e)
  {
    this.m_okButton.Enabled = true;
  }

  private void m_frameValueCtrl_TypeInvalid(object sender, EventArgs e)
  {
    this.m_okButton.Enabled = false;
  }

  private void m_stringValueCtrl_TextChanged(object sender, EventArgs e)
  {
    this.m_okButton.Enabled = true;
  }

  private void m_stringValueCtrl_KeyPress(object sender, KeyPressEventArgs e)
  {
    if (e.KeyChar != '\r')
      return;
    CCApSetLocationsParametersApp.LastEditedAttributeId = ((AttributeComboBoxItem) this.m_attributesList.SelectedItem).AttributeId;
    this.SetEditedAttributeOnLocations();
    ((Form) this).Close();
  }

  private void m_frameValueCtrl_KeyPress(object sender, KeyPressEventArgs e)
  {
    if (e.KeyChar != '\r')
      return;
    CCApSetLocationsParametersApp.LastEditedAttributeId = ((AttributeComboBoxItem) this.m_attributesList.SelectedItem).AttributeId;
    this.SetEditedAttributeOnLocations();
    ((Form) this).Close();
  }

  private void m_enumValueCtrl_SelectedIndexChanged(object sender, EventArgs e)
  {
    if (this.m_enumValueCtrl.SelectedIndex == -1)
      this.m_okButton.Enabled = false;
    else
      this.m_okButton.Enabled = true;
  }

  private void m_enumValueCtrl_KeyPress(object sender, KeyPressEventArgs e)
  {
    if (e.KeyChar != '\r' || this.m_enumValueCtrl.SelectedIndex == -1)
      return;
    CCApSetLocationsParametersApp.LastEditedAttributeId = ((AttributeComboBoxItem) this.m_attributesList.SelectedItem).AttributeId;
    this.SetEditedAttributeOnLocations();
    ((Form) this).Close();
  }

  private void m_numericValueCtrl_ValueChanged(object sender, EventArgs e)
  {
    this.m_okButton.Enabled = true;
  }

  private void m_numericValueCtrl_KeyPress(object sender, KeyPressEventArgs e)
  {
    if (e.KeyChar == '\r')
    {
      CCApSetLocationsParametersApp.LastEditedAttributeId = ((AttributeComboBoxItem) this.m_attributesList.SelectedItem).AttributeId;
      this.SetEditedAttributeOnLocations();
      ((Form) this).Close();
    }
    else
    {
      if (e.KeyChar == '\u001B' || e.KeyChar == '\t' || this.m_okButton.Enabled)
        return;
      this.m_okButton.Enabled = true;
    }
  }
}
